package com.fstec.ks.master.dao.jdbc.setter;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.springframework.jdbc.core.PreparedStatementSetter;

import com.fstec.ks.master.dao.cond.ServerRoundCond;
import com.sinotn.spring.jdbc.PageQuery;

public class ServerRoundSetter implements PreparedStatementSetter {
	private ServerRoundCond cond;
	private PageQuery pageQuery;

	public ServerRoundSetter(ServerRoundCond cond) {
		this.cond = cond;
	}

	public void setPageQuery(PageQuery pageQuery) {
		this.pageQuery = pageQuery;
	}
	private void andJoin(StringBuilder sb){
		if(sb.length()==0){
			sb.append(" WHERE ");
		}else{
			sb.append(" AND ");
		}
	}
	public String getWhere(){
		if(this.cond==null) return "";
		StringBuilder sb=new StringBuilder();
		if(this.cond.getExamServerId()!=null){
			this.andJoin(sb);
			sb.append("exam_server_id=?");
		}
		return sb.toString();
	}

	@Override
	public void setValues(PreparedStatement ps) throws SQLException {
		if(this.cond!=null){
			int index=1;
			if(this.cond.getExamServerId()!=null){
				ps.setString(index++, this.cond.getExamServerId());
			}
		}
		if(this.pageQuery!=null){
			this.pageQuery.setValues(ps);
		}
	}
}
